class Book < ActiveRecord::Base
  has_many :borrows, :dependent => :destroy
  has_many :users, :through => :borrows

  attr_accessible :author, :category_id, :code, :current_quantity, :description, :image_url, :numborrowed, :numviewed, :price, :quantity, :title

  validates :code, :presence => true, :uniqueness => true, :length => { :minimum => 8 }
  validates :title, :presence => true, :uniqueness => { :case_sensitive => false, :scope => :author }
  validates :price, :numericality => true
  validates :quantity, :numericality => { :only_integer => true }
end
